package com.google.code.jcooky.rpc.compiler;

import java.io.File;
import java.io.IOException;
import java.util.Map;

import org.apache.commons.io.FileUtils;

public abstract class Processor {
	public static class ProcessException extends RuntimeException {
		public ProcessException(String s) {
			super(s);
		}

		public ProcessException(String s, Throwable e) {
			super(s, e);
		}
	}

	private String namespace;
	private File basedir;
	
	protected String arguments_layout;
	
	public Processor() throws IOException {
		arguments_layout = StringUtils.read("arguments.layout");
	}

	public String getNamespace() {
		return namespace;
	}

	public void setNamespace(String namespace) {
		this.namespace = namespace;
	}

	public File getBasedir() {
		return basedir;
	}

	public void setBasedir(File basedir) {
		this.basedir = basedir;
	}
	
	protected void write(String strbuf, String filename) {
		String path = getBasedir().getPath() + "/" + filename + ".java";
		try { 
			FileUtils.write(new File(path), strbuf, "UTF-8"); 
		} catch(IOException e) {
			throw new RuntimeException(e);
		}
	}

	public abstract void process(Map<String, Object> attributes) throws ProcessException;
}
